﻿using AnQinFrameWorkAPI.Entity.Blog.DTO.BlogUser;
using AnQinFrameWorkAPI.Entity.Blog.View.BlogUser;
using AnQinFrameWorkAPI.Service.Blog;
using FrameWork.Entity;
using Microsoft.AspNetCore.Mvc;

namespace AnQinFrameWorkAPI.Controllers.Blog;

/// <summary>
///     博客用户API
/// </summary>
[Route("api/[controller]")]
[ApiController]
[ApiExplorerSettings(GroupName = "Blog")]
public class BlogUserController : ControllerBase
{
    // 业务服务接口
    private readonly BlogUserService _blogUserService;

    // 构造注入
    public BlogUserController(BlogUserService blogUserService)
    {
        _blogUserService = blogUserService;
    }

    /// <summary>
    ///     获取博客用户列表
    /// </summary>
    /// <param name="searchDTO">查询条件</param>
    [ProducesResponseType(typeof(BlogUserView), 200)]
    [HttpGet]
    public async Task<IActionResult> GetBlogUserList([FromQuery] BlogUserSearchDTO searchDTO)
    {
        var response = await _blogUserService.GetBlogUserList(searchDTO);
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     新增博客用户
    /// </summary>
    /// <param name="addDTO">用户数据</param>
    [HttpPost]
    public async Task<IActionResult> AddBlogUser([FromBody] BlogUserAddDTO addDTO)
    {
        var response = await _blogUserService.AddBlogUser(addDTO);
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     更新博客用户
    /// </summary>
    /// <param name="updateDTO">用户数据</param>
    [HttpPut]
    public async Task<IActionResult> PutBlogUser([FromBody] BlogUserUpdateDTO updateDTO)
    {
        var response = await _blogUserService.PutBlogUser(updateDTO);
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     删除博客用户
    /// </summary>
    /// <param name="deleteDTO">删除参数</param>
    [HttpDelete]
    public async Task<IActionResult> DeleteBlogUser([FromBody] SingleIdDTO deleteDTO)
    {
        var response = await _blogUserService.DeleteBlogUser(deleteDTO);
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     获取博客用户信息
    /// </summary>
    [HttpGet("HandShake")]
    public async Task<IActionResult> BlogHandShake()
    {
        var response = await _blogUserService.BlogHandShake();
        return StatusCode(response.Status, response);
    }
}